home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8835 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.0 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is &Variable (declared as: char Variable[10])?
  5. Date: 04 Mar 1996 15:10:26 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Mar4081026@qcd.lanl.gov>
  8. References: <4gqpa1$3h9@alcor.usc.edu> <4gtab6$acb@ceylon.gte.com>
  9.     <4gvksnINNnug@anvil.ugrad.cs.ubc.ca>
  10.     <TANMOY.96Feb29100937@qcd.lanl.gov>
  11.     <4hdtfcINN4l3@keats.ugrad.cs.ubc.ca>
  12. NNTP-Posting-Host: qcd.lanl.gov
  13. Mime-Version: 1.0
  14. Content-Type: text
  15. In-reply-to: c2a192@ugrad.cs.ubc.ca's message of 3 Mar 1996 21:01:32 -0800
  16.  
  17. In article <4hdtfcINN4l3@keats.ugrad.cs.ubc.ca>
  18. c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
  19.  
  20. <snip>
  21. KK: myarray is an expression whose evaluation calls for the generation
  22. of a value, 
  23. KK: whose type is pointer to char and which points to the first
  24. element of myarray. 
  25. KK: However, the expression myrray also has other attributes. It is an
  26. lvalue which 
  27. KK: can be the subject of sizeof() and & operators, which are not
  28. interested in 
  29. KK: computing the pointer value,  but which look at the type and
  30. storage attributes 
  31. KK: of myarray itself. It is not a modifiable lvalue, hence it cannot
  32. be assigned 
  33. KK: to.
  34. <snip>
  35. KK: The bottom line is that it's not necessary to view the subjects of
  36. & and sizeof 
  37. KK: as special cases; expressions are the same in the context of these
  38. operators as 
  39. KK: they are anywhere else, and can be seen as producing the same
  40. values. 
  41.  
  42. One nit: One should not think of the value of the operand of sizeof
  43. because it is _not_ evaluated. Thus *(char*)0 is clearly undefined
  44. according to the standard, but sizeof *(char*)0 is valid. 
  45.  
  46. The difference you are trying to make between `value context' and
  47. `object context' (or `lvalue context') is a good way of understanding
  48. what is going on. In fact, I prefer this method of explaining it to
  49. beginners as well; though strictly speaking it is incorrect.
  50.  
  51. It is actually a pity that the standard does not take that approach,
  52. and so even though you will get the same set of valid expressions: for
  53. invalid one's you will get different reasons for them being
  54. invalid. Thus if a are b are an arrays, by your logic the statement
  55. `a=b' is ruled out because the lvalue a is not modifiable and also
  56. because b is in a value context and hence does not remain an array to
  57. be assigned to a. On the other hand 6.2.2.1 makes clear that this is
  58. invalid because a in this context is not an lvalue!!! The difference
  59. is not important to most people: but I thought I would point it out
  60. just once.
  61.  
  62. Cheers
  63. Tanmoy
  64. --
  65. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  66. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  67. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  68. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  69. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  70. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  71.